<template>
	<view class="">
		<!-- 404页面 -->
		<view class="noData" v-if="netWorkType == 'none'">
			<noData @handle="refresh"></noData>
		</view>
		<view style="width:100%;" v-if="netWorkType != 'none'">
			<view class="noaddress" v-if="data.addressList.length==0">
				<!-- <image src="../../../static/img/noorder.png"></image> -->
				<view class="text">
					没有收货地址
				</view>
			</view>
			<view class="content" v-else>
				<view class="tips" v-if="tipsBtn==true">
					<view class="mod">
						为了更好的识别你最近的租赁门店，请选择你的位置，请注意
						不在租赁地址归还，系统将收取适量的<text class="conspicuous">调度费</text>
					</view>
					<view class="x" style="padding: 10rpx;" @click="tipsBtnClick">
						X
					</view>
				</view>

				<view class="list">

					<view class="row" v-if="switch_select==0" v-for="(row,index) in data.addressList" :key="index" @tap="select(row)">
						<!-- <view class="left">
							<view class="head">
								{{row.head}}
							</view>
						</view> -->
						<view class="center">
							<view class="name-tel">
								<view class="name">{{row.name}}</view>
								<view class="tel">{{row.tel}}</view>
							</view>
							<view class="address">
								{{row.province_name}}{{row.city_name}}{{row.area_name}} {{row.detail}}
							</view>
						</view>
						<view class="right">

							<view class="btn yes" v-if="data.storeaddress.store_name==row.store_name">
								已选
							</view>
							<view class="btn no" v-else>
								选择
							</view>
						</view>
					</view>

					<view class="row" v-if="switch_select==1" v-for="(row,index) in data.addressList" :key="index" @tap="select(row)">

						<view class="center">
							<view class="name-tel">
								<view class="name">{{row.store_name}}</view>
								<view class="tel">{{row.tel}}</view>
							</view>
							<view class="address">
								{{row.content}}
							</view>
						</view>
						<view class="right">
							<!-- <view class="iconfont" v-if="row.isDefault">
								&#xe6e4;
							</view> -->
							<view class="btn yes" v-if="data.storeaddress.store_name==row.store_name">
								已选
							</view>
							<view class="btn no" v-else>
								选择
							</view>
						</view>
					</view>

				</view>
			</view>



		</view>
	</view>
</template>

<script>
	//公共api接口封装方法
	//获取网络状态
	import {
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				isSelect: false,
				//网络状态
				networkStatus: true,
				//接口数据
				data: {
					addressList: [],
					storeaddress: ''
				},
				// 线下归还
				productId: '',
				tipsBtn: true,
				// 线上归还
				latitude: '',
				longitude: '',
				editId: '',
				editStoreId: '',
				// 判断
				switch_select: 0,
				// 线下租赁
				sid: '',
				pid: '',
				bid: '',
				cid: '',
				lat1: '',
				lng1: '',
				scene:'',
			};
		},
		components: {

		},
		computed: {
			//注册网络状态
			...mapGetters(['netWorkType'])
		},
		onShow() {

			//设置门店自提地址
			uni.getStorage({
				key: 'seleteStore',
				success: (e) => {
					this.data.storeaddress = e.data;
				},
				fail: () => {
					//初始默认地址
					console.log("无地址")
					this.data.storeaddress = ''
				}
			})
		},
		onLoad(e) {
			console.log(e)
			console.log('9898')
			// if (e.type == 'select') {
			this.isSelect = true;
			// }
			// 接收其他页面传过来的值
			// 配送订单
			if (typeof e.product_id != "undefined") {
				this.productId = e.product_id
				this.getList()
				this.switch_select = 0
			}
			// 扫码归还
			if (typeof e.latitude != "undefined") {
				this.latitude = e.latitude

				if (typeof e.longitude != "undefined") {
					this.longitude = e.longitude

					if (typeof e.editId != "undefined") {
						this.editId = e.editId

						if (typeof e.editStoreId != "undefined") {
							this.editStoreId = e.editStoreId
							console.log("chuanzhi")
							this.getListof()
							this.switch_select = 1
						}
					}
				}
			}
		 
			// 扫码租赁
			if (typeof e.sid != "undefined") {
				this.sid = e.sid

				if (typeof e.pid != "undefined") {
					this.pid = e.pid

					if (typeof e.bid != "undefined") {
						this.bid = e.bid

						if (typeof e.cid != "undefined") {
							this.cid = e.cid
							if (typeof e.lat1 != "undefined") {
								this.lat1 = e.lat1
								if (typeof e.lng1 != "undefined") {
									this.lng1 = e.lng1
									if(typeof e.scene != "undefined"){
										this.scene=e.scene;
										this.getProduct()
										this.switch_select = 1
									}
									
								}
							}
						}
					}
				}
			}

		},
		methods: {
			// 刷新的方法
			refresh() {
				this.getList()
			},
			// 提示开关
			tipsBtnClick() {
				console.log("点击了开关" + this.tipsBtn)
				if (this.tipsBtn == true) {
					this.tipsBtn = false
				} else {
					this.tipsBtn = true
				}

			},
			// 配送订单
			getList() {
				//初始常用地址
				const _this = this
				//console.log(66)				
				var opt = {
					url: '/store/deliverStoreList',
					data: {
						product_id: _this.productId,
					},
					success: function(res) {
						//console.log(res)
						if (res.status == 1) {
							_this.data.addressList = res.data.list
							//console.log(_this.data.goods)
						} else {
							uni.showToast({
								icon: 'none',
								title: res.message
							});
						}

					}
				};

				_this.$service.GetApi(opt)

			},
			// 扫码归还
			getListof() {
				const _this = this
				//#ifdef  MP-WEIXIN || MP-ALIPAY || APP-PLUS
				uni.getLocation({
					//#ifdef  MP-WEIXIN || APP-PLUS
					type: 'gcj02', //返回可以用于uni.openLocation的经纬度
					//#endif
					success: function(res) {
						_this.latitude = res.latitude;
						_this.longitude = res.longitude;
						//console.log(999)
						//津头
						// _this.latitude = 22.797131;
						// _this.longitude = 108.339878;
						//瓯宁
						// _this.latitude = 22.804960;
						// _this.longitude = 108.325000;
						//工谷
						// _this.latitude = 22.880333;
						//  _this.longitude = 108.284576;
						var opt = {
							url: '/order/getPayStore',
							data: {
								lat1: _this.latitude,
								lng1: _this.longitude,
								store_id: _this.editId,
								rent_store_id: _this.editStoreId,

							},
							success: function(res) {
								console.log("chengg")
								if (res.status == 1) {
									_this.data.addressList = res.data.list
								} else {
									let options = {
										msg: res.message,
										type: 'danger'
									};
									_this.$refs.toast.showTips(options);

								}
							}
						};
						_this.$service.GetApi(opt)
					},
					fail: function() {
						let options = {
							msg: 'GPS未开启',
							type: 'danger'
						};
						_this.$refs.toast.showTips(options);
						return
					}
				});
				//#endif	
			},
			// 扫码租赁
			//获取产品详情
			getProduct() {
				const _this = this
			 
				//提交ajax
				var opt = {
					url: '/product/detail',
					data: {
						sid: _this.sid,
						pid: _this.pid,
						bid: _this.bid,
						cid: _this.cid,
						lat1: _this.lat1,
						lng1: _this.lng1,
						scene:_this.scene
					},
					success: function(res) {
						//onsole.log(res)
						if (res.status == 1) {
							_this.data.addressList = res.data.nearby_store


						} else {
							let options = {
								msg: res.message,
								type: 'danger'
							};
							_this.$refs.toast.showTips(options);

						}
					}
				};

				this.$service.GetApi(opt)
			},
			// 返回地址
			select(row) {
				//是否需要返回地址(从订单确认页跳过来选收货地址)
				if (!this.isSelect) {
					return;
				}
				uni.setStorage({
					key: 'seleteStore',
					data: row,
					success() {
						uni.navigateBack();
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./return.scss";
</style>
